﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
using System.IO.Ports;
using Microsoft.Office.Core;
using Excel = Microsoft.Office.Interop.Excel;
using MasterDatabase;
using System.Collections;

namespace JobsDisplay
{
    public partial class Form1 : SQL_APPL
    {
        public DataTable JobsTracking_dtb = new DataTable();
        public DataSet JobsTracking_ds = new DataSet();
        public SqlDataAdapter JobsTracking_da;

        public DataTable WST_Tracking_dtb = new DataTable();
        public DataSet WST_Tracking_ds = new DataSet();
        public SqlDataAdapter WST_Tracking_da;

        public DataTable Load_Job_Tracking(string empl_id, DateTime date)
        {
            string date_str = date.ToString("dd MMM yyyy");
            string time_str = date.ToString("HH:mm:ss");

            string sql_cmd = @"SELECT * FROM [JOB_ASSIGNMENT_DB].[dbo].[P007_P008_Tracking] ";
            sql_cmd += " WHERE Empl_ID = '" + empl_id + "'";
            sql_cmd += " AND Date = '" + date_str + "'";
            sql_cmd += " AND '" + time_str + "' BETWEEN From_Time AND To_Time";

            if (JobsTracking_dtb != null)
            {
                JobsTracking_dtb.Clear();
            }
            JobsTracking_dtb = Get_SQL_Data(MasterDatabase_Connection_Str, sql_cmd, ref JobsTracking_da, ref JobsTracking_ds);
            return JobsPlan_dtb;
        }

        public DataTable Load_WST_Tracking(string line_id, string wst_id, DateTime current)
        {
            string date_str = current.ToString("dd MMM yyyy");
            string time_str = current.ToString("HH:mm:ss");
            string shift_id = Get_Shift_ID(current);
            string sql_cmd = @"SELECT * FROM [JOB_ASSIGNMENT_DB].[dbo].[P007_P008_Tracking] ";
            sql_cmd += " WHERE LineID = '" + line_id + "'";
            if (wst_id != "")
            {
                sql_cmd += " AND WST_ID = '" + wst_id + "'";
            }
            sql_cmd += " AND Date = '" + date_str + "'";
            //sql_cmd += " AND '" + time_str + "' BETWEEN From_Time AND To_Time";
            sql_cmd += " AND Shift_Name = '" + shift_id + "'";
            sql_cmd += " ORDER by [From_Time] DESC";

            if (WST_Tracking_dtb != null)
            {
                WST_Tracking_dtb.Clear();
            }
            WST_Tracking_dtb = Get_SQL_Data(MasterDatabase_Connection_Str, sql_cmd, ref WST_Tracking_da, ref WST_Tracking_ds);
            return WST_Tracking_dtb;
        }
    }
}